home *** CD-ROM | disk | FTP | other *** search
- /* Copyright, 1990, Regents of the University of Colorado */
- /* This program performs a vertical smoothing, with the matrix partitioned
- * by columns, with multiple columns per processor. The matrix is of size
- * M x N, where N must be a multiple of P. */
-
- #include "dino.h"
-
- #define max(x,y) (x > y ? x : y)
- #define min(x,y) (x < y ? x : y)
-
- #define M 16
- #define N 16
- #define P 4
-
- environment node[P:id] {
-
- composite smooth (a, in iter)
- double distributed a[M][N] map BlockColOverlap;
- int iter;
-
- {
- int i, j, k; /* Looping variables */
-
- /* Repeat the smoothing process iter times */
- for (i = 0; i < iter; i++) {
-
- /* Send out your data and receive it back again, if not the first
- * iteration */
- if (i != 0) {
-
- a[][<id * N/P,(id + 1) * N/P - 1>]# =
- a[][<id * N/P,(id + 1) * N/P - 1>];
-
- /* ==> This statement sends out those columns
- of a which are "home" on this
- environment. Only those columns which
- have copies on another environment
- are actually sent. */
-
- a[][<max(id * N/P - 1, 0),min((id + 1) * N/P, N - 1)>]#;
-
- /* ==> Receives the "copy" rows. Only those
- columns which are copies are actually
- sent. The max() and min() calls
- deal with the edge cases */
-
- }
-
- /* Perform the computation, but only on non-edge columns */
- for (j = 0; j < M; j++)
- for (k = max(id * N/P, 1); k <= min((id + 1) * N/P - 1, N - 2); k++)
- a[j][k] = (a[j][k-1] + a[j][k+1]) / 2;
-
- }
- }
- }
-
- environment host {
-
- void main ()
-
- {
- double a[M][N]; /* Input data */
- int iter; /* Holds the iteration count */
-
- int i, j; /* Looping variables */
-
- /* Set up the initial data for a[][] */
- for (i = 0; i < M; i++)
- for (j = 0; j < N; j++)
- a[i][j] = (i + 1)*(j + 1);
- for (i = 0; i < M; i++)
- for (j = 1; j < N - 1; j++)
- a[i][j] = 0;
-
- /* Set up the variable which will contain the number of iterations */
- iter = 300;
-
- /* Print out the initial data */
- printf ("Initial data for a:\n");
- for (i = 0; i < M; i++) {
- for (j = 0; j < N; j++)
- printf ("%6.2f", a[i][j]);
- printf ("\n");
- }
-
- /* Perform the computation */
- smooth (a[][], iter)#;
-
- /* Printout the results */
- printf ("Result data for a:\n");
- for (i = 0; i < M; i++) {
- for (j = 0; j < N; j++)
- printf ("%6.2f", a[i][j]);
- printf ("\n");
- }
- }
- }
-
-